1436A - Reorder - CodeForces Solution


math *800

Please click on ads to support us..

Python Code:

t = int(input())
for _ in range(t):
    n,m = list(map(int,input().split()))
    a = list(map(int,input().split()))
    s = 0
    for i in a:
        s+=i 
    if s == m:
        print("YES")
    else:
        print("NO")

C++ Code:

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
*                       BISMILLAHIR RAHMANIR RAHIM                           *
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define s(x)       sort(x.begin(),x.end())
#define all(a)     a.begin(),a.end()
#define rall(a)    a.rbegin(),a.rend()
#define rev(a)     reverse(all(a))
#define rv(x)      reverse(x.begin(),x.end())
#define g(v)       sort(v.begin(),v.end(),greater<int>())
#define rs(v)      sort(v.rbegin(),v.rend())
#define pf         printf
#define sf         scanf
#define pb         push_back
#define GCD(x,y)   __gcd(x, y)
#define ll         long long
#define lld        long double
#define sz(x)      x.size()
#define ff         first
#define sd         second
#define mp         make_pair
#define py         cout<<"YES"<<endl
#define pn         cout<<"NO"<<endl
#define ii         pair<ll,ll>
#define iii        pair<ii,int>
#define cii        pair<char, ii>
#define pq         map<char,vector<ll>>
#define CheckMate  return;
using namespace std;
const int N = 100001;

const ll MOD=1e9+7;

vector <ll> primeList;
vector<bool>visit(N);
void seive()
{
    ll num=N;
    for(int i=4; i<=num; i+=2) visit[i]=true;
    primeList.push_back(2);

    for(int i=3; i<=num; i+=2)
    {
        if(visit[i]==false)
        {
            primeList.push_back(i);
            if(sqrt(num)>=i)
            {
                for(int j=i+i; j<=num; j+=i) visit[j]=true;
            }
        }
    }
}

vector<ll> divisors(ll n)
{
    vector<ll> d;
    for(ll i=1; i*i<=n; i++)
    {
        if(n%i==0)
        {
            if(n/i!=i) d.pb(n/i);
            d.pb(i);

        }
    }
    return d;
}

vector<ll> primefactor(int num)
{
    vector <ll> primes;
    int x = num;
    for(int i=0; primeList[i]*primeList[i]<=num; i++)
    {

        while(num%primeList[i]==0)
        {
            num=num/primeList[i];
            primes.push_back(primeList[i]);
            if(num==1)break;
        }
    }
    if(num!=1) primes.push_back(num);
    // for(int i=0; i<primes.size()-1; i++) cout<<primes[i]<<'*';
    //cout<<primes[primes.size()-1]<<" = "<<x<<endl;
    s(primes);
    return primes;
}

vector<ll> primefact(ll n)
{
    vector<ll>pf;
    while(n%2==0)
    {
        pf.push_back(2);
        n/=2;
    }

    ll ans=sqrt(n);

    for(ll i=3; i<=ans; i+=2)
    {
        while(n%i==0)
        {
            pf.push_back(i);
            n/=i;
        }
    }
    if(n>2) pf.push_back(n);
    s(pf);
    return pf;
}


bool check(ll n)
{
    int a=0,b=0;
    while(n>0)
    {
        if(n%10==4) a++;
        else b++;
        n/=10;
    }
    if(a==b) return true;
    return false;
}


void precalc(ll n)
{
//    if(check(n)) v.pb(n);
    if(n<1e9)
    {
        precalc(n*10+4);
        precalc(n*10+7);
    }

}
ll bigmod(ll a,ll b,ll m)
{
    if(b==0) return 1%m;
    ll x=bigmod(a,b/2,m);
    x=(x*x)%m;
    if(b%2==1) x=(x*a)%m;
    return x;
}
ll calculation(vector<int>& v)
{
    ll n=sz(v),cnt=0,sum=0;
    for(int i=n-1; i>=0; i--)
    {
        if(v[i]==0) cnt++;
        else sum+=cnt;
    }
    return sum;
}


int f(int n)
{
    return (n*(n+1))/2;
}

//----------------- Lets START --------------------//



void oacm()
{
    int n,k;
    cin>>n>>k;
    int sum=0;
    for(int i=0; i<n; i++)
    {
        int a;
        cin>>a;
        sum+=a;
    }
    sum==k ? py:pn;
}


int main()
{
    fast
    seive();
    int t=1;
    cin>>t;
    while(t--)
    {
        oacm();
        //cout<<endl;
    }

}

//---------------- THE END -----------------//






Comments

Submit
0 Comments
More Questions

1108B - Divisors of Two Integers
1175A - From Hero to Zero
1141A - Game 23
1401B - Ternary Sequence
598A - Tricky Sum
519A - A and B and Chess
725B - Food on the Plane
154B - Colliders
127B - Canvas Frames
107B - Basketball Team
245A - System Administrator
698A - Vacations
1216B - Shooting
368B - Sereja and Suffixes
1665C - Tree Infection
1665D - GCD Guess
29A - Spit Problem
1097B - Petr and a Combination Lock
92A - Chips
1665B - Array Cloning Technique
1665A - GCD vs LCM
118D - Caesar's Legions
1598A - Computer Game
1605A - AM Deviation
1461A - String Generation
1585B - Array Eversion
1661C - Water the Trees
1459A - Red-Blue Shuffle
1661B - Getting Zero
1661A - Array Balancing